/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vale.services;

import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.faces.context.FacesContext;
import org.apache.log4j.Logger;

/**
 *
 * @author Gabriel Bran gbran.u@gmail.com
 */
public class Services {

    @Produces
    public Logger produceLogger(InjectionPoint injectionPoint) {
        return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
    }

    @Produces
    @LoggedUser
    public String getRemoteUser(InjectionPoint injectionPoint) {
        return FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
    }

    @Produces
    @HttpRequestParameter
    public String getHttpRequestParameter(InjectionPoint injectionPoint) {
        String name = injectionPoint.getAnnotated().getAnnotation(HttpRequestParameter.class).value();
        if ("".equals(name)) {
            name = injectionPoint.getMember().getName();
        }
        return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
    }
}
